package com.globallogic.strelchuk.multi.entity;

import com.globallogic.strelchuk.multi.exception.TableSizeException;
import com.globallogic.strelchuk.multi.util.Formatter;
import com.globallogic.strelchuk.multi.util.Multiplicator;

/**
 * @author olena.strelchuk
 */

/**
 * Entity of Multiplication Table for specified number
 */
public class SquareMultiplicationTable extends AbstractMultiplicationTable {

	private int[][] squareTable;

	public SquareMultiplicationTable(int tableSize) throws TableSizeException {
		super(tableSize);
	}

	/**
	 * Initialize Square Table
	 */
	@Override
	public void initTable() {
		// square table with int elements
		squareTable = new int[getTableSize()][getTableSize()];
		generateMultiplicationTable();
	}

	/**
	 * Generate MultiplicationTable with specified table size
	 */
	private void generateMultiplicationTable() {
		for (int i = 1; i <= getTableSize(); i++) {
			for (int j = 1; j <= getTableSize(); j++) {
				squareTable[i - 1][j - 1] = Multiplicator.doMultiply(i, j);
			}
		}
	}

	/**
	 * toString Method for MultiplicationTable
	 */
	@Override
	public String toString() {
		return Formatter.formatSquareTable(this);
	}

	public int[][] getSquareTable() {
		return squareTable;
	}
}
